package designpattern.command.llm.command;

import designpattern.command.llm.model.StringBuf;

public class DeleteCommand implements Command {
    private final StringBuf stringBuf;
    private final int position;
    private final int length;
    private String deletedText;

    public DeleteCommand(StringBuf stringBuf, int position, int length) {
        this.stringBuf = stringBuf;
        this.position = position;
        this.length = length;
    }

    @Override
    public void execute() {
        deletedText = stringBuf.delete(position, length);
    }

    @Override
    public void undo() {
        stringBuf.insert(position, deletedText);
    }
}